package com.edu.zju.scs.panacea.mapper.resource;

import com.edu.zju.scs.panacea.entity.resource.Package;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: Yue Liang
 * @Date: 2018-12-26 21:13
 */

@Repository
public interface PackageMapper {
    @Select("SELECT * FROM res_package WHERE id = #{id}")
    @Results(id="packageMap", value={
            @Result(id=true,property="id",column="id"),
            @Result(property="name",column="name"),
            @Result(property="sellerId",column="seller_id"),
            @Result(property="state",column="state")})
    Package selectPackage(Long id);

    @Select("SELECT * from res_package where seller_id = #{sellerId}")
    @ResultMap(value = "packageMap")
    List<Package> selectPackageBySeller(Long sellerId);


    @Delete("DELETE FROM res_package where id = #{id}")
    long deletePackage(Long id);

    @Insert("INSERT INTO res_package(name, seller_id, state) VALUES (#{name}, #{sellerId}, 0)")
    @Options(useGeneratedKeys=true)
    long insertPackage(Package resPackage);

    @Update({ "update res_package set name = #{name}, seller_id = #{sellerId}, remarks = #{remarks} where id = #{id}" })
    long updatePackage(Package resPackage);
}
